
using Microsoft.EntityFrameworkCore;
using System.Reflection;
using 天离安全_天擎.Tl_DbContext_Api;
using 天离安全_天擎.Tl_EntitySqlIte;
using 天离安全_天擎.Tl_SerVices;

namespace 天离安全_天擎
{
    /// <summary>
    /// 主入口
    /// </summary>
    public class Program
    {
        /// <summary>
        /// 主函数
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            // 显示注释 2025/06/16
            builder.Services.AddSwaggerGen(c =>
            {
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath, true);
            });

            // 添加内存缓存服务
            builder.Services.AddMemoryCache();

            // 注册您的缓存服务
            builder.Services.AddSingleton<GetMemoryCaching_Services>();

            // 连接本地数据库=全量
            var databasePath = Path.Combine(AppContext.BaseDirectory, "data", "tianli.db");
            builder.Services.AddDbContext<AppDbContext>(options =>
                options.UseSqlite($"Data Source={databasePath}"));

            // 注册 CrackPassWord_Services
            builder.Services.AddApplicationServices(Assembly.GetExecutingAssembly());

            // 注册控制器服务
            builder.Services.AddControllers();

            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseHttpsRedirection();

            app.UseAuthorization();

            app.MapControllers();

            app.MapControllers();

            app.Run();
        }
    }
}
